﻿using Models.Models;
using Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using yymbDAL;

namespace yymbBLL
{
    public class IndexManger
    {
        private IndexService db;
        public IndexManger()
        {
            db = new IndexService();
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public User Login(string name, string pwd)
        {
            return db.Login(name, pwd);
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool Register(User user)
        {
            return db.Register(user) > 0;
        }
        /// <summary>
        /// 初始化信息表(Information)
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public bool AddInfo(Information info)
        {
            return db.InsertInfo(info) > 0;
        }
        /// <summary>
        /// 首页最新评论用户（大家正在说）
        /// </summary>
        /// <returns></returns>
        public List<Comment> GetNewComm()
        {
            return db.SelNewComm();
        }
        /// <summary>
        /// 关注度TOP10
        /// </summary>
        /// <returns></returns>
        public IEnumerable<IGrouping<string, User_rs>> GetTopFollow()
        {
            return db.selTopFollow();
        }
        /// <summary>
        /// 显示新注册用户前20位
        /// </summary>
        /// <returns></returns>
        public List<Information> GetNewUser()
        {
            return db.SelNewUser();
        }
        /// <summary>
        /// 根据邮件和密码获取用户ID
        /// </summary>
        /// <param name="email"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public int GetOneUser(string email, string pwd)
        {
            return db.SelOneUser(email, pwd);
        }
        /// <summary>
        /// 显示4条点赞数加转发数最高的微博
        /// </summary>
        /// <returns></returns>
        public List<Microblog> GetNewMBlogs()
        {
            return db.SelNewMBlogs();
        }
        /// <summary>
        /// 显示点赞数加转发数最高的微博
        /// </summary>
        /// <returns></returns>
        public List<Microblog> GetMBlogs()
        {
           return db.GetMBlogs();
        }
        /// <summary>
        /// 获取所有微博的数量
        /// </summary>
        /// <returns></returns>
        public int SumWB()
        {
            return db.SumWB();
        }
        /// <summary>
        /// 通过微博id查询这条微博的所有评论
        /// </summary>
        /// <param name="MbID"></param>
        /// <returns></returns>
        public List<Comment> GetComm(int MbID)
        {
            return db.GetComm(MbID);
        }
        /// <summary>
        /// 添加评论
        /// </summary>
        /// <param name="comment"></param>
        /// <returns></returns>
        public bool AddComment(Comment comment)
        {
            return db.AddComment(comment) > 0;
        }
        /// <summary>
        /// 删除评论
        /// </summary>
        /// <param name="commid"></param>
        /// <returns></returns>
        public bool DelComment(int commid)
        {
            return db.DelComment(commid)>0;
        }
        /// <summary>
        /// 转发微博
        /// </summary>
        /// <param name="mbid"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public bool AddFwmb(Microblog micr)
        {
            return db.AddFwmb(micr) > 0;
        }
        /// <summary>
        /// 根据转发的ID查询被转发的那条微博信息
        /// </summary>
        /// <param name="fwID"></param>
        /// <returns></returns>
        public Microblog FwMic(int? fwID)
        {
            return db.FwMic(fwID);
        }
    }
}
